using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using MySql.Data.MySqlClient;


namespace DAL
{
    public class PasserelleMySql
    {
        public static MySqlConnection connexion;

        public static void ouvertureConnexion(string chaineConnexion)
        {
            connexion = new MySqlConnection(chaineConnexion);
            connexion.Open();
        }

        public static void fermetureConnexion()
        {
            connexion.Close();
        }

        public static DataTable executionRequete(string req)
        {
            // Utilisation d'un DataAdapter
            MySqlDataAdapter unDataAdapter = new MySqlDataAdapter(req, PasserelleMySql.connexion);
            // Remplissage du DataSet avec le résultat du DataAdapter
            DataSet unDataSet = new DataSet();
            unDataAdapter.Fill(unDataSet);
            //Sélection du 1er DataTable
            DataTable unDataTable = unDataSet.Tables[0];
            return unDataTable;
        }

        public static void executionMaj(string req)
        {
            // type de maj : insertion, suppression, modification
            MySqlCommand cmdMaj = new MySqlCommand(req, PasserelleMySql.connexion);
            cmdMaj.ExecuteNonQuery();
        }
    }
}
